package com.example.music.dialog;

import android.app.Application;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;

import com.example.music.App;
import com.example.music.MainActivity;
import com.example.music.R;
import com.example.music.adapter.HyListAdapter;
import com.example.music.databinding.DialogListBinding;
import com.example.music.entity.DataMusic;

import java.util.List;

public class BottomDialog {
    public void showCustomizeDialog(Context content, App app) {
        Dialog bottomDialog = new Dialog(content, R.style.BottomDialog);
        DialogListBinding binding = DialogListBinding.inflate(LayoutInflater.from(content));;
        bottomDialog.setContentView(binding.getRoot());
        ViewGroup.LayoutParams layoutParams = binding.getRoot().getLayoutParams();
        layoutParams.width = content.getResources().getDisplayMetrics().widthPixels;
        binding.getRoot().setLayoutParams(layoutParams);
        bottomDialog.getWindow().setGravity(Gravity.BOTTOM);
        bottomDialog.getWindow().setWindowAnimations(R.style.BottomDialog_Animation);
        binding.close.setOnClickListener(v -> bottomDialog.dismiss());
        List<DataMusic> dataMusics = app.getDataMusics();
        binding.clear.setOnClickListener(v -> {
            app.clearAll();
            dataMusics.clear();
            binding.listMusic.setAdapter(new HyListAdapter(app,dataMusics,app.getPn()));
            bottomDialog.dismiss();
        });
        app.addDataMusics((DataMusic) null, new App.MusicEvent() {
            @Override
            public void onCompletion(String lyric) {
                binding.listMusic.setAdapter(new HyListAdapter(app,dataMusics,app.getPn()));
            }

            @Override
            public void onCurrent(DataMusic dataMusic) {

            }

            @Override
            public void onStateChange(Boolean bool) {

            }

            @Override
            public void onNull() {

            }

            @Override
            public void onData(List<DataMusic> dataMusics, int i) {
                binding.listMusic.setAdapter(new HyListAdapter(app,dataMusics,i));
                binding.title.setText("播放列表("+dataMusics.size()+")");
            }

        });
        binding.title.setText("播放列表("+dataMusics.size()+")");
        binding.listMusic.setAdapter(new HyListAdapter(app,dataMusics,app.getPn()));
        bottomDialog.show();
    }
}
